import GameDefin, { EntityState } from "src/Ldz_GameCore/GeneralScripts/GameDefine";
import HoneyBeesBase from "src/Ldz_GameCore/HoneyBee/HoneyBeeManager/HoneyBeesBase";
import CombatantManageBase from "../../FSM_Base/CombatantManageBase";
import CombatantStateBase from "../../FSM_Base/CombatantStateBase";



export default class PlayerBeeStateAttack extends CombatantStateBase {
    BoolIsFire: boolean = false;

    Url: string;

    public Init(SelfObj: Laya.Sprite3D, _CombatantManageBase: CombatantManageBase)                  //初始化虚函数
    {
        super.Init(SelfObj, _CombatantManageBase);
        this.m_EntityState = EntityState.Attack;
    }
    public OnEnter()               //进入状态的虚函数
    {
        this.PlayAnimation(GameDefin.AnimationName_Attack);
        this.BoolIsFire = true;
        this.AttackTime = 0;
    }
    AttackTime: number;
    LastPos: Laya.Vector3;
    public OnExecute()             //执行状态的虚函数
    {
        //当前状态不是 这个脚本的时候 就退出
        if ((this.m_CombatantManageBase.m_CurStateBase.m_EntityState != EntityState.Attack)) {
            return;
        }
        this.AttackTime += (Laya.timer.delta / 1000);
        //this.m_Animator.getControllerLayer().getCurrentPlayState().normalizedTime 
        if (this.AttackTime > 0.5 && this.BoolIsFire) {
            if (this.m_CombatantManageBase.m_TargetObj != null && !this.m_CombatantManageBase.m_TargetObj.destroyed) {
                let Tar: HoneyBeesBase = this.m_CombatantManageBase.m_TargetObj.getComponent(HoneyBeesBase);
                console.log("进行了攻击");
                if (Tar != null && !Tar.destroyed) {
                    console.log("进入扣血");
                    if (Tar.BeAttacked(this.m_CombatantManageBase.m_SoldiersBase)) {
                        this.m_CombatantManageBase.m_TargetObj = null;
                    }
                }
            }
            this.BoolIsFire = false;

        } else if (this.AttackTime > 1) {
            this.m_CombatantManageBase.m_Attackinterval = this.m_CombatantManageBase.m_SoldiersBase.m_TempAttributeBase.m_HitSpeed;
            this.m_CombatantManageBase.ChangeState(EntityState.Idle);
        }

    }
    public OnExit()                //推出状态的虚函数
    {
        super.OnExit();
    }
    protected GetEntityState(): EntityState {
        if (this.m_CombatantManageBase.m_CurStateBase != null) {
            return this.m_CombatantManageBase.m_CurStateBase.m_EntityState;
        }
        return EntityState.EnTity_NULL;
    }
}
